package top.lyjwn.ajui.network;

import java.util.Map;

import okhttp3.FormBody;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * post请求体
 *
 * @author luoyujie
 */
public class PostRequestBody {

    private String url;

    private RequestBody requestBody;

    private MultipartBody multipartBody;
    public PostRequestBody() {
    }

    public PostRequestBody(String url, RequestBody requestBody) {
        this.url = url;
        this.requestBody = requestBody;
    }


    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public RequestBody getRequestBody() {
        return requestBody;
    }

    public void setRequestBody(RequestBody requestBody) {
        this.requestBody = requestBody;
    }

    public MultipartBody getMultipartBody() {
        return multipartBody;
    }

    public void setMultipartBody(MultipartBody multipartBody) {
        setRequestBody(multipartBody);
        this.multipartBody = multipartBody;
    }

    public void setRequestBody(Map<String, Object> map) {
        setRequestBody(mapToRequestBody(map));
    }

    private RequestBody mapToRequestBody(Map<String, Object> map) {
        FormBody.Builder builder = new FormBody.Builder();
        if (map != null) {
            for (String key : map.keySet()) {
                builder.add(key, map.get(key).toString());
            }
            return builder.build();
        } else {
            return builder.build();
        }
    }
}

